import java.util.Arrays;

public class InsertSort {

    public static void selectSort(int[] arr) {
        int left = 0 ;
        int right = arr.length -1;
        int count = 0;
        while(left < right) {
            int maxIndex = left;
            int minIndex = left;

            for(int i = left + 1; i <= right; i++) {
                if(arr[i] > arr[maxIndex]) {
                    maxIndex = i;
                }

                if(arr[i] < arr[minIndex]) {
                    minIndex = i;
                }
            }
            System.out.println(" minIndex:" + minIndex + " left:" + left + " maxIndex:" + maxIndex + " right:" + right);
            swap(arr, minIndex, left);
            count ++;
            System.out.println("第" + count + " 次排序：" + Arrays.toString(arr));
            if (maxIndex == left) {
                maxIndex = minIndex;
                System.out.println("maxIndex  left 相等 : left:" + left + " maxIndex:" + maxIndex);
            }
            swap(arr,maxIndex,right);
            count ++;
            System.out.println("第" + count + " 次排序：" + Arrays.toString(arr));
            left ++;
            right --;
        }
    }

    private static void swap(int[] arr, int a, int b) {
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;

    }

    private static final String MESSAGE = "csdn";
    public static void main(String[] args) {
        int[] arr = {9,8,7,6,5,4,3,2,1};
        selectSort(arr);

        System.out.println(Arrays.toString(arr));

        String a = "cs" + "dn";
        String b = "cs";
        String c = "dn";
        System.out.println(a == MESSAGE);
        System.out.println((b+c)== MESSAGE);
    }
}
